//
//  FindPeopleCell.m
//  MyProject
//
//  Created by 石小强 on 2018/4/16.
//  Copyright © 2018年 yanjiaming. All rights reserved.
//

#import "FindPeopleCell.h"

@implementation FindPeopleCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.starView.emptyStarColor = UIColorFromRGB(0xBFBFBF);
    self.starView.emptyStarImage = [UIImage imageNamed:@"ic_stars_没选中没选中Unselected"];
    self.starView.filledStarImage = [UIImage imageNamed:@"ic_stears_Selected"];
    self.starView.halfStarImage = [UIImage imageNamed:@"ic_stars_Halfselected"];
    self.starView.maximumValue = 5;
    self.starView.minimumValue = 0;
    self.starView.value = 2.5;
    self.starView.allowsHalfStars = YES;
//    self.starView.accurateHalfStars = YES;
    self.starView.continuous = YES;
    
    self.iconImgV.layer.cornerRadius = 34.5;
    self.iconImgV.layer.masksToBounds = YES;
}

- (void)setModel:(IncumbentModel *)model {
    _model = model;
    
    // 保过标签
    if (model.hasAssurePassService) {
        self.tagImgV.hidden = NO;
    } else {
        self.tagImgV.hidden = YES;
    }
#warning 测试
//    self.tagImgV.hidden = NO;
    
    // 头像
    
    // 名称
    if (model.nickName && model.nickName.length > 0) {
        self.nameL.text = model.nickName;
    } else {
        self.nameL.text = @"137xxxx909";
    }
//    self.nameL.text = model.nickName;
    
    // 职位和时间
    NSDateFormatter *ft = [[NSDateFormatter alloc] init];
    [ft setDateFormat:@"YYYY"];
    NSDate *dateNow = [NSDate date];
    NSString *currentTimeStr = [ft stringFromDate:dateNow];
    NSInteger time = [currentTimeStr integerValue] - [model.entryTime integerValue];
    [self.iconImgV sd_setImageWithURL:[NSURL URLWithString:ImageURL(model.headImg)] placeholderImage:PlaceholderImagePeople];
    self.positionAndTimeL.text = [NSString stringWithFormat:@"%@ | 已在职%zd年", model.positionName, time];
    self.addressAndCompanyL.text = [NSString stringWithFormat:@"%@ | %@", model.region, model.companyName];
    
    
    CGFloat itemH = (kScreenWidth - 34) * 409 / 321;
//    self.line.frame = CGRectMake(0, 237 * itemH / 409 + 50, kScreenWidth - 34, 1);
    self.topImageTopHeight.constant = 54 * itemH / 409 + 10;
    self.lineTopHeight.constant = 237 * itemH / 409 - 8;
    
    NSArray *skills = [model.adeptSkill componentsSeparatedByString:@","];
    NSString *skillResult = @"";
    if (skills.count > 0) {
        for (NSString *str in skills) {
            skillResult = [NSString stringWithFormat:@"%@、%@", skillResult, str];
        }
    }
    self.skillL.text = skillResult.length > 0 ? [skillResult substringFromIndex:1] : @"暂未提供";
    self.numberpeopleL.text = [NSString stringWithFormat:@"帮助过%@人 | 满意度", model.helpedCount];
    self.starView.value = [self getStarWithSatisfaction:model.degreeOfSatisfaction];
//    self.starView.enabled = NO;
    
    self.lineLeftDistance.constant = 20 * 409 / 321;
    self.lineRightDistance.constant = 20 * 409 / 321;
}

- (IBAction)starViewValueChanged:(id)sender {
    self.starView.value = [self getStarWithSatisfaction:self.model.degreeOfSatisfaction];
}

- (CGFloat)getStarWithSatisfaction:(NSString *)degreeOfSatisfaction {
    CGFloat result = [degreeOfSatisfaction floatValue];
    
    if (result >= 0 && result < 0.25) {
        return 0;
    } else if (result >= 0.25 && result < 0.75) {
        return 0.5;
    } else if (result >= 0.75 && result < 1.25) {
        return 1;
    } else if (result >= 1.25 && result < 1.75) {
        return 1.5;
    } else if (result >= 1.75 && result < 2.25) {
        return 2;
    } else if (result >= 2.25 && result < 2.75) {
        return 2.5;
    } else if (result >= 2.75 && result < 3.25) {
        return 3;
    } else if (result >= 3.25 && result < 3.75) {
        return 3.5;
    } else if (result >= 3.75 && result < 4.25) {
        return 4;
    } else if (result >= 4.25 && result < 4.75) {
        return 4.5;
    } else {
        return 5;
    }
    
}

@end
